#!/usr/bin/perl


# This file is part of qorg11 blog

# qorg11 blog is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# qorg11 blog is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with qorg11 blog.  If not, see <https://www.gnu.org/licenses/>.


use SQLite::DB;
my $db = SQLite::DB->new('articles.sqlite');
$db->connect;
my $NumEntradas = $db->select_one_row("select * from blog")->{ID};
my $NumEntradasMax = $db->select_one_row("select * from blog order by id desc")->{ID};




print "Content-type: text/xml";
print "
    <?xml version='1.0' encoding='UTF-8' ?>\n
    <rss version='2.0'>\n

    <channel>\n
    <title>qorg11 blog</title>\n
    <link>https://qorg.duckdns.org/blog</link>\n
    <description>blog qorg11</description>\n";
my $content, $id, $title;
for(my $x = $NumEntradasMax; $x >= $NumEntradas; $x-- ) {
    my $entradas = $db->select_one_row("select * from blog where id == $x");
    $content = $entradas->{CONTENT};
    $id = $entradas->{ID};
    $title = $entradas->{TITLE};
    $content =~ s/</&lt;/g;
    $content =~ s/>/&gt;/g;
    print "<item>\n";
    print "<title>$title</title>\n";
    print "<link>https://qorg.duckdns.org/blog#$id</link>\n";
    print "<description>$content</description>\n";
    print "</item>";


}
print "</channel>\n";
print "</rss>\n";
